package com.xujie.chat.client;

import com.xujie.chat.client.handler.ClientInit;
import com.xujie.chat.message.NettyConstant;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Scanner;

/**
 * @author Xujie
 * @since 2024/12/28 22:13
 **/


public class ClientServer {
	private static final String menu = "1.发送消息：send clientId msg\n2.显示在线用户：show\n3.退出：quit\n";

	public static void main(String[] args) throws InterruptedException, IOException {
		MyClient myClient = new MyClient();
		Thread thread = new Thread(myClient);
		thread.start();
		Scanner scanner = new Scanner(System.in);

		while (true) {
			System.out.println(menu);
			String msg = scanner.nextLine();
			if (msg == null) {
				continue;
			}
			if ("quit".equals(msg.toLowerCase())) {
				myClient.close();
				scanner.close();
				System.exit(1);
			} else if ("show".equals(msg.toLowerCase())) {
				myClient.showOnlineClients();
			} else if (msg.contains("send")) {
				String[] split = msg.split(" ");
				myClient.sendMsgToClient(split[1], split[2]);
			} else if ("my".equals(msg.toLowerCase())) {
				myClient.showMyClientId();
			}
			//myClient.sendMsg(msg);
		}
	}

}
